<template>
<div class="app-container">
  <loading v-show="loading"></loading>
  <el-card class="box-card searchFormStyle" style="margin-bottom:1%;">
    <div slot="header" class="clearfix">
      <span>日志管理</span>
    </div>
    <div class="text item">
      <el-form ref="searchData" :model="searchData" label-width="130px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="日志类型">
              <el-input v-model="searchData.operateLogType"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="操作账号">
              <el-input v-model="searchData.operateAccount"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item>
              <el-button type="primary" 
              icon="el-icon-search" 
              v-if="permissionHandle('operatelog:getList')"
              @click="btnsearchOperateLog">查 询</el-button>
              <el-button type="primary" 
              icon="el-icon-refresh" 
              v-if="permissionHandle('operatelog:getList')"
              @click="resetSearch">重 置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </el-card>
  <el-card class="box-card" style="margin-bottom:1%;">
    <div slot="header" class="clearfix">
      <span>日志列表</span>
    </div>
    <el-table
      :data="tableData"
      border
      ref="tableData"
      style="width: 100%;margin-bottom:1%;"
      class="detailTables"
    >
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" block class="demo-table-expand">
            <el-form-item label="操作内容">
              <span>{{ props.row.operateContent }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column
        label="操作账号"
        width="180">
        <template slot-scope="scope">
            {{ scope.row.operateAccount }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作IP"
        width="180">
        <template slot-scope="scope">
            {{ scope.row.operateIp }}
        </template>
      </el-table-column>
      <el-table-column
        label="日志类型"
      >
        <template slot-scope="scope">
            {{ scope.row.operateLogType }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作时间"
      >
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.operateTime }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" :paginations="paginations"></pagination>
</el-card>
</div>
</template>
<script>
import Loading from '@/components/loading/loading'
import pagination from '@/components/pagination/index'
import { searchOperateLog } from '@/api/resource/operatelog'
export default {
  components: {
    Loading,
    pagination
  },
  data() {
    this.permissionHandle = this.$permissionHandle
    return {
      paginations: {
        totalNum: 0,
        currentPage: 1,
        pageSize: 10
      },
      searchData: {
        operateLogType: '',
        operateAccount: '',
        pageSize: '10',
        pageNum: '1'
      },
      loading: false,
      tableData: [],
      // 新增角色数据
      dialogFormVisible: false, // 新增弹出框状态
      // 列表所选数据集合
      rules: {
      }
    }
  },
  created() {
    this.searchOperateLog()
  },
  methods: {
    // 按钮查询
    btnsearchOperateLog() {
      this.searchData.pageNum = 1
      this.paginations.currentPage = 1
      this.searchOperateLog()
    },
    // 查询参数
    searchOperateLog() {
      this.loading = true
      return new Promise((resolve, reject) => {
        searchOperateLog(this.searchData).then(response => {
          this.tableData = response.data.items
          this.paginations.totalNum = parseInt(response.data.itemsTotalCount)
          this.loading = false
          resolve()
        }).catch(error => {
          this.loading = false
          reject(error)
        })
      })
    },
    // 输入参数查询之后
    blurSearch(value) {
      this.paginations.currentPage = 1
      this.searchOperateLog()
      this.searchData.pageNum = 1
    },
    handleSizeChange(val) {
      this.searchData.pageSize = val
      this.searchOperateLog()
    },
    handleCurrentChange(val) {
      this.searchData.pageNum = val
      this.searchOperateLog()
    },
    resetForm(formName) {
      // this.dialogFormVisible = false
      this.$refs[formName].resetFields()
    },
    resetSearch() {
      this.searchData.operateLogType = ''
      this.searchData.operateAccount = ''
      this.searchOperateLog()
    }
  }
}
</script>
<style lang="scss">
 .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 100%;
  }
  .detailTables .el-form-item__content{line-height: 40px;}
</style>
